package day01;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class ByteArrayInputOutputStreamDemo01 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数据");
        String msg = sc.nextLine();
        ByteArrayInputStream bin = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
        ByteArrayOutputStream bout = new ByteArrayOutputStream();

        int c = -1;
        while((c=bin.read())!=-1) {
            bout.write(c);
        }

        String data = bout.toString();
        System.out.println("从内存中读取的数据："+data);
        bout.writeTo(new FileOutputStream(new File("D:\\1\\byteArray.txt")));
        bout.close();
    }
}
